package com.example.springboot_admin.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.springboot_admin.pojo.Posts;
import com.example.springboot_admin.pojo.Topics;
import com.example.springboot_admin.service.ITopicsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author svblack
 * @since 2024-09-14
 */
@RestController
@RequestMapping("/topics")
public class TopicsController {
    @Autowired
    ITopicsService topicsService;
    @RequestMapping("/page")
    IPage<Topics> page(@RequestParam(defaultValue = "1") int page,
                      @RequestParam(defaultValue = "5") int limit,
                      @RequestParam(required = false) String query){
        IPage<Topics> pagelist=topicsService.page(
                new Page<>(page, limit), new QueryWrapper<Topics>()
                        .like(query != null && !query.isEmpty(), "name", query));
        return pagelist;
    }
    @RequestMapping("/del")
    Integer del(Integer topic_id){
        return topicsService.removeById(topic_id)?0:1;
    }
    @RequestMapping("delMult")
    Integer delMult(@RequestBody List<Integer> ids){
        System.out.println("ids:"+ids);
        topicsService.removeByIds(ids);
        return 0;
    }
}

